package api

import (
	"gateway/basic/config"
	__ "gateway/basic/proto"
	"gateway/handler/request"
	"gateway/handler/resp"
	"github.com/gin-gonic/gin"
)

func SendSms(c *gin.Context) {
	//接收参数
	var req request.SendSms
	if err := c.ShouldBind(&req); err != nil {
		resp.Error(c, 400, "参数接收错误", err.Error())
		return
	}
	//业务逻辑
	_, err := config.ClearClient.SendSms(c, &__.SendSmsReq{Mobile: req.Mobile})
	if err != nil {
		resp.Error(c, 400, "服务层错误", err.Error())
		return
	}
	resp.Success(c, true)
}

func Register(c *gin.Context) {
	//接收参数
	var req request.Register
	if err := c.ShouldBind(&req); err != nil {
		resp.Error(c, 400, "参数接收错误", err.Error())
		return
	}
	//业务逻辑
	_, err := config.ClearClient.Register(c, &__.RegisterReq{
		Mobile:   req.Mobile,
		Password: req.Password,
		SmsCode:  req.SmsCode,
	})
	if err != nil {
		resp.Error(c, 400, "服务层错误", err.Error())
		return
	}
	resp.Success(c, true)
}

func Login(c *gin.Context) {
	//接收参数
	var req request.Login
	if err := c.ShouldBind(&req); err != nil {
		resp.Error(c, 400, "参数接收错误", err.Error())
		return
	}
	//业务逻辑
	_, err := config.ClearClient.Login(c, &__.LoginReq{
		Mobile:   req.Mobile,
		Password: req.Password,
	})
	if err != nil {
		resp.Error(c, 400, "服务层错误", err.Error())
		return
	}
	resp.Success(c, true)
}
